from apps.interface.util.utils import *
from apps.interface.models.interfacecase import InterfaceCase


class ConfigBusiness(object):

    @classmethod
    def parse_func(cls, case_id):
        """根据用例id获取函数
        :param case_id:
        :return:
        """
        case_data = InterfaceCase.query.filter_by(id=case_id,
                                                  status=InterfaceCase.ACTIVE).first()
        # case_var.append(json.loads(case_data.variable) if case_data.variable else [])
        # 用例信息的函数文件
        case_func = ['func_list.{}'.format(f.replace('.py', '')) for f in
                     json.loads(case_data.func_address)]
        return case_func

    @classmethod
    def parse_variable(cls, case_id):
        """根据用例id获取变量
        :param case_id:
        :return:
        """
        case_data = InterfaceCase.query.filter_by(id=case_id,
                                                  status=InterfaceCase.ACTIVE).first()
        case_variable = json.loads(case_data.variable) if case_data.variable else ''
        return case_variable
